<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/common/common.jsp" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>修改商品分类</title>
	<link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/css/basic.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/static/plugins/layer/skin/default/layer.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/plugins/validationEngine/css/validationEngine.jquery.css" rel="stylesheet" type="text/css">
     <style type="text/css">
        select{
        	width: 200px;
        	line-height: 33px;
        	height: 33px;

        }
    </style>
</head>
<body>
<div class="content">
    <form class="form-horizontal" id="addForm">
    	<input type="hidden" id="id" name="id" value="${phProductClassifyVo.id }"/><!-- 层级 -->
    	<input type="hidden" id="classifyLevel" name="classifyLevel" value="1"/><!-- 层级 -->
    	<input type="hidden" id="parentId" name="parentId" value="0"/><!-- 父Id -->
        <div class="form-group">
            <label for="roleName" class="col-sm-4 control-label">上级分类:</label>
            <div class="col-sm-3">
                <select id="first" onchange="getClass(this.options[this.selectedIndex].value);" <c:if test="${quote == 1}">disabled="disabled"</c:if>>
                	<option value="-1" selected="selected">一级分类</option>
                	<c:forEach var="item" varStatus="status" items="${pcL1List}">
                   	 <option value="${item.id }" 
                   	  <c:choose>
                       <c:when test="${item.id == phProductClassifyVo.parentId}">selected="selected"</c:when>
                       <c:when test="${item.id == pClassifyParent.parentId}">selected="selected"</c:when>
                       </c:choose>
                   	 >${item.classifyName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="col-sm-3">
                <select id="second" <c:if test="${quote == 1}">disabled="disabled"</c:if>>
               	 <option value="-1" selected="selected">二级分类</option>
               	 <c:forEach var="item" varStatus="status" items="${pcL2List}">
                   	 <option value="${item.id }" <c:if test="${item.id == phProductClassifyVo.parentId}"> selected="selected"</c:if>>${item.classifyName}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="classifyName" class="col-sm-4 control-label"><span style="color: red;">*</span>分类名称:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control validate[required]" id="classifyName" name="classifyName" data-fun="classifyNameFun"
                     value="${phProductClassifyVo.classifyName}"  placeholder="请输入分类名称"/>
            </div>
        </div>
        <div class="form-group">
            <label for="sort" class="col-sm-4 control-label">排序:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control validate[custom[integer],min[1]]" id="sort" name="sort" value="${phProductClassifyVo.sort}" placeholder="请输入排序"/>
            </div>
        </div>
<!--         <div class="form-group" > -->
<!--             <label for="status" class="col-sm-4 control-label">是否启用:</label> -->
<!--             <div class="col-sm-3"> -->
<%--                未启用: <input type="radio" name="status" id="status" value="1" <c:if test="${phProductClassifyVo.status == 1}"> checked="checked"</c:if>/> --%>
<%--                 启用:<input type="radio" name="status" id="status" value="2"  <c:if test="${phProductClassifyVo.status == 2}"> checked="checked"</c:if>/> --%>
<!--              </div> -->
<!--         </div> -->
        <div class="col-sm-8" >
            <label  class="col-sm-6 control-label">描述:</label>
            <div class="col-sm-3">
                <input type="text" style="width: 400px;" value="${phProductClassifyVo.description}" class="form-control" name="description" id="description"  placeholder="请输入描述"/>
            </div>
        </div>
        
        <div class="form-group">
            <div class="col-sm-10" style="text-align: center;">
                <button type="button" id="addBtn" class="btn btn-primary">修改</button>
                <button type="button" onclick="javascript:window.location.href='${ctx}/api/productClassify/listPage'" class="btn btn-primary" >返回</button>
            </div>
        </div>

       <!--  <input type="hidden" name="id" value="1"/> -->
    </form>
</div>
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<script src="${ctx}/static/plugins/layer/layer.js"></script>
<script src="${ctx}/static/plugins/validationEngine/jquery.validationEngine-zh_CN.js"></script>
<script src="${ctx}/static/plugins/validationEngine/jquery.validationEngine.js"></script>
<script>
    $(function () {
    	$("#addForm").validationEngine({ 
    		promptPosition: "topRight", 
    		validationEventTriggers:"keyup blur", 
    		success :  false,
    		failure : function() { callFailFunction()  }
   		});
    	$("#addBtn").click(function(){
	    	var flag = $("#addForm").validationEngine("validate");
	    	if(!flag){
	     		return false;
	    	} 
	    	var level1ParentId = $("#first").val();
	    	if(null != level1ParentId && level1ParentId != -1 ){
	    		$("#parentId").val(level1ParentId);
	    		$("#classifyLevel").val(2);
	    	}
	    	var level2ParentId = $("#second").val();
	    	if(null != level2ParentId && level2ParentId != -1 ){
	    		$("#parentId").val(level2ParentId);
	    		$("#classifyLevel").val(3);
	    	}
	    	var obj = $("#addForm").serialize();
	    	console.log(obj);
    		//提交数据
        	$.ajax({
        		async       : false,
        		type 		: "POST",
        	    url		    : "${ctx}/api/productClassify/updateClassify",
        		data 		: $("#addForm").serialize(),
        		success 	: function( d ) {
        			if(d.code == 200){
        				layer.msg('修改商品分类成功',{icon: 1, time: 2000},
        						function(index){
    		            	window.location.href="${ctx}/api/productClassify/listPage";
    		            });
        			} else {
        				layer.msg('修改商品分类失败',{icon: 2});
        			}
        		}
        	});
    	});
    });
    
	function getClass(id){
		if(id!=""){
			$.ajax({url:'${ctx}/api/productClassify/selectClass?id='+id,dataType:"json",type:"post",success:savecallbackOne,error:function(data){
					layer.alert("与服务器连接中断");
	    		}});
		}
	}
	function savecallbackOne(data){
		console.log(data.data);
		$("#second").find("option").remove();
		$("#second").prepend("<option value='-1'>二级分类</option>")
		for(var i=0; i<data.data.length;i++){
			if(data.data[i].id == ${phProductClassifyVo.id}){
				continue;
			}
			$("#second").append("<option value='"+data.data[i].id+"'>"+data.data[i].classifyName+"</option>");
		}
				
	}
</script>
</body>
</html>